package com.loong.common.rabbitmq.dto.base;

import com.loong.common.rabbitmq.enums.RepositoryEvent;
import lombok.*;

import java.io.Serializable;

/**
 * 数据库信息发生变化，同步索引
 */
@Setter
@Getter
@Builder
@ToString
@AllArgsConstructor
public class RepositoryEventDto<T> implements Serializable {
    /**
     * @see RepositoryEvent
     */
    private Short eventCode;
    private T data;

    public  static <T> RepositoryEventDto<T> buildWithCreate(T data){
       return RepositoryEventDto.<T>builder().eventCode(RepositoryEvent.CREATE.getCode()).data(data).build();
    }
    public static <T> RepositoryEventDto<T> buildWithDelete(T data){
        return RepositoryEventDto.<T>builder().eventCode(RepositoryEvent.DELETE.getCode()).data(data).build();
    }
    public static <T> RepositoryEventDto<T> buildWithUpdate(T data){
        return RepositoryEventDto.<T>builder().eventCode(RepositoryEvent.UPDATE.getCode()).data(data).build();
    }
    public   RepositoryEventDto(){

    }
    public static class RepositoryEventDtoBuilder<T>{
        private RepositoryEventDtoBuilder<T> builder(){
            return new RepositoryEventDtoBuilder<T>();
        }
    }
}
